import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import qs from 'qs'

const app = createApp(App)

// 配置 axios
axios.defaults.baseURL = 'http://localhost:8890'
axios.interceptors.request.use(config => {
  const token = localStorage.getItem('adminToken')
  if (token) {
    config.headers.Authorization = `Bearer ${token}`
  }
  return config
})

app.config.globalProperties.$axios = axios
app.config.globalProperties.$qs = qs
app.config.globalProperties.$getLocalStorage = (key) => {
  const value = localStorage.getItem(key)
  return value ? JSON.parse(value) : null
}
app.config.globalProperties.$setLocalStorage = (key, value) => {
  localStorage.setItem(key, JSON.stringify(value))
}
app.config.globalProperties.$removeLocalStorage = (key) => {
  localStorage.removeItem(key)
}

app.use(store)
app.use(router)
app.mount('#app')
